import Toast from '@vant/weapp/toast/toast';
import dayjs from "dayjs"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    initData:[] as any,
    price:0,
    createTime:"",
    userName:'',
    number:null,
    tips:""
  },
  init(){

  },
  infoChange(e:any){
    let name = e.currentTarget.dataset.name
    let value = e.detail
    if(name=="name"){
      this.setData({
        userName:value
      })
    }
    if(name=="number"){
      this.setData({
        number:value
      })
    }
    if(name=="tips"){
      this.setData({
        tips:value
      })
    }
  },
  payfor(){
    let userName = this.data.userName
    let number = this.data.number
    let tips = this.data.tips
    let name = ""
    let cover = this.data.initData[0].cover
    let price = this.data.price
    this.data.initData.forEach((item:any)=>{
        name = `${item.name} X ${item.count}`
    })
    if(number&&userName){
    getApp().globData.dinnerInfo={ userName,number,tips,name,cover,price}
      wx.navigateTo({
        url:"/pages/dinnerPay/dinnerPay"
      })
    }else{
      Toast.fail('信息不完整');
    }
  },
  onLoad(){
    const eventChannel = this.getOpenerEventChannel()
    let createTime = dayjs().format("YYYY/MM/DD/HH:MM")  
    eventChannel.on('context', ({price,data})=> {
       this.setData({
         initData:data,
         price,
         createTime
       })
    })
  }
})